var a = require("../../@babel/runtime/helpers/createForOfIteratorHelper"), t = getApp();

Page({
    data: {
        active: 0,
        page: 1,
        finished: !1,
        americanFans: [],
        statistics: {},
        rankingList: [ "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/plugin/gold_medal.png", "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/plugin/silver_medal.png", "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/plugin/bronze_medal.png" ],
        current_member: !1
    },
    onLoad: function(a) {
        this.getData(), this.getStatistics();
    },
    getData: function() {
        var e = this;
        if (!this.data.finished) {
            var n = 1 == this.data.active ? "plugin.powder-value.frontend.stat.detailed" : "plugin.powder-value.frontend.stat.ranks", s = t.getNetAddresss(n);
            t._getNetWork({
                url: s,
                data: {
                    page: this.data.page
                },
                success: function(t) {
                    if (1 !== t.data.result) return wx.showToast({
                        title: t.data.msg
                    }), !1;
                    var n = t.data.data, s = !1, i = [];
                    if (0 == e.data.active) {
                        (0 === n.ranks.data.length || n.ranks.data.length < n.ranks.per_page || n.ranks.current_page === n.ranks.last_page) && (s = !0), 
                        i = e.data.americanFans.concat(n.ranks.data), n.current_member.constructor === Object && 1 == e.data.page && (i.unshift(n.current_member), 
                        e.setData({
                            current_member: !0
                        }));
                        var r, c = a(i);
                        try {
                            for (c.s(); !(r = c.n()).done; ) {
                                var g = r.value;
                                g.member.username = g.member.username.slice(0, 2) + "****";
                            }
                        } catch (a) {
                            c.e(a);
                        } finally {
                            c.f();
                        }
                    } else (0 === n.data.length || n.data.length < n.per_page || n.current_page === n.last_page) && (s = !0), 
                    i = e.data.americanFans.concat(n.data);
                    e.setData({
                        finished: s,
                        americanFans: i,
                        page: ++e.data.page
                    });
                }
            });
        }
    },
    getStatistics: function() {
        var a = this, e = t.getNetAddresss("plugin.powder-value.frontend.stat.index");
        t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 == e.result && (a.setData({
                    statistics: e.data
                }), wx.setNavigationBarTitle({
                    title: a.data.statistics.diy_name
                }));
            }
        });
    },
    onReachBottom: function() {
        this.getData();
    },
    changeTabs: function(a) {
        this.setData({
            page: 1,
            finished: !1,
            active: a.detail.name,
            americanFans: []
        }), this.getData();
    }
});